// pages/detail/detail.js
const app = getApp();
const audio = wx.getBackgroundAudioManager()
const detailHttp = require('../../modules/detailHttp');
const playHttp = require('../../modules/playHttp');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    datas:{},
    mp3:{},
    isPlay:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    var id = options.id;
    var res = await detailHttp.getDetailData({
      id :id,
    });
    console.log(res);
    var datas={};
    datas.name=res.data.program.mainSong.name;
    datas.pic=res.data.program.coverUrl;
    datas.content=res.data.program.description;
    datas.id=res.data.program.mainSong.id;
    var music=await playHttp.getPlayData({id:datas.id});
    var mp3={};
    mp3.url=music.data.data[0].url;
    mp3.name=music.data.data[0].type;
    console.log(music)
    this.setData({
      datas,
      mp3
    })

  },
  handleMp3(){
    var url=this.data.mp3.url;
    var name=this.data.mp3.name;
    var isPlay=this.data.isPlay;
    isPlay=!isPlay
    this.setData({
      isPlay
    });
    if(!isPlay){
     audio.src=url;
      audio.title=name;
    }else{
      audio.pause()
    }
  }
})